package com.deco.service.VariableSpeed;

import com.deco.dao.domain.table.Variablespeed;
import com.deco.domain.vo.ti.TiDelcoLevelidModelVo;
import com.deco.logic.variableSpeed.VariableSpeedLogic;
import com.deco.service.ti.TiDelcoLevelidModelService;
import com.free.common.vo.ResultModel;
import com.free.ext.logger.FreeLogger;
import com.free.ext.logger.FreeLoggerFactory;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明：
 * 创建人：Q879095880
 */
@Service
public class VarialbleSpeedService {
    @Autowired
    VariableSpeedLogic variableSpeedLogic;

    private static final FreeLogger LOG = FreeLoggerFactory.getLogger(VarialbleSpeedService.class);

    /**
     * 变速箱首页
     * @param variablespeed
     * @return
     */
    public ResultModel getList(Variablespeed variablespeed){
        return ResultModel.success(variableSpeedLogic.getList(variablespeed));
    }

    /**
     * 模糊查询
     * @param brand
     * @return
     */
    public ResultModel getLike(String brand){
        return ResultModel.success(variableSpeedLogic.getLike(brand));
    }

    /**
     * 获取车辆年份信息
     * @param variablespeed
     * @return
     */
    public ResultModel getByBrand(Variablespeed variablespeed){
        return ResultModel.success(variableSpeedLogic.getByBrand(variablespeed));
    }



    public ResultModel getInfo(Variablespeed variablespeed){
        List<String> datas  = Arrays.asList(variablespeed.getVehiclDate().split("-"));
        if(StringUtils.isNotEmpty(datas.get(0))){
            variablespeed.setVehicleStartDate(datas.get(0)+"/01");
        }
        if(datas.size() == 2 && StringUtils.isNotEmpty(datas.get(1))){
            variablespeed.setVehicleEndDate(datas.get(1)+"/01");
        }
        return ResultModel.success(variableSpeedLogic.getInfo(variablespeed));
    }

    /**
     * 根据车型获取年份
     * @param variablespeed
     * @return
     */
    public ResultModel getByvehicletype(Variablespeed variablespeed){
        return ResultModel.success(variableSpeedLogic.getByvehicletype(variablespeed));
    }


    /**
     * 通过力洋id获取车辆数据
     * @param
     * @return
     */
    public Map<String,Object> getByvehcleId(String levelId,String tid){
        List<Variablespeed> variablespeeds =  variableSpeedLogic.getByvehcleId(levelId,tid);
        LOG.info("VIN查询编号：{}查到的汽车数量{}",levelId, variablespeeds.size());
        if(variablespeeds == null || variablespeeds.size() ==0){
            return null;
        }
        Map<String,Object> res = new HashMap<>();
        res.put("carInfo",variablespeeds.get(0));
        if(res != null){
            res.put("vechileNo",levelId);
        }
        return res;
    }

    public List<Variablespeed> getByLevelId(String levelId){
        return variableSpeedLogic.getByLevelId(levelId);
    }


}
